package com.roy.workbench.bookmark.schedule;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * Created by elloxxn on 12/6/2017.
 */
@Component
public class Jobs {
    private static Logger logger = LoggerFactory.getLogger(Jobs.class);

    public final static long ONE_Second = 60000l;

    int[] delays = new int[]{6,2,1,1,1};
    int index = 0;

    int[] delays2 = new int[]{6,2,11,1,1};
    int index2 = 0;
/*
    @Scheduled(fixedDelay = ONE_Second)
    public void delayJob() {
        //logger.info(">>>>>>>>>>>>>>>>>>>>>>begin delay job.....");

        try {
            Thread.sleep(delays[index++] * 1000);
            if (index > 4) index = 0;
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //logger.info("<<<<<<<<<<<<<<<<<<<<<<end delay job");
    }
*/
    @Scheduled(fixedRate = ONE_Second)
    public void rateJob() {
        logger.info(">>>>>>>>>>>>>>>>>>>>>>begin rate job.....");

        try {
            long a = delays2[index2++] * 1000L;
            System.out.println("=================sleep " + a + " ms====================");
            Thread.sleep(a);
            if (index2 > 4) index2 = 0;
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        logger.info("<<<<<<<<<<<<<<<<<<<<<<end rate job");
    }

}
